package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.SearchQueryObject;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：高级查询多个功能
 *
 * @package: cn.wolfcode.trip.api.controller
 * @author: wjh
 * @date: 2019/05/29 16:08
 * 总结:
 */
@RestController
@RequestMapping("searchs")
public class SearchController {

    @Autowired//攻略文章
    private IStrategyService strategyService;
    @Autowired
    private IStrategyDetailService strategyDetailService;
    @Autowired//游记
    private ITravelService travelService;

    /**
     * 高级查询接口
     * 1 资源 /searchs
       2 请求方式 get
       3 请求参数 keyword,pills
       4 返回结果 map
     */
    @GetMapping
    public Map list(SearchQueryObject qo) {
        HashMap<String, Object> map = new HashMap<>();
        if(qo.getPills() == null || qo.getPills() == 1){
            //查询攻略文章
            PageInfo<StrategyDetail> details = strategyDetailService.listContentByKeyword(qo);
            map.put("details", details);
        }else if(qo.getPills() == 2){
            //查询游记
            PageInfo<Travel> travels = travelService.listContentByKeyword(qo);
            map.put("travels", travels);
        }
        map.put("tag", qo.getPills());
        return map;
    }

}